package com.jshcbd.modules.asset.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jshcbd.modules.asset.entity.ReceiveEntity;
import com.jshcbd.modules.asset.vo.AssetUseVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author zhoucd
 * @date
 * @description
 */
public interface ReceiveMapper extends BaseMapper<ReceiveEntity> {


    List<ReceiveEntity> getReceiveByAssetId(String[] ids);



    @Select("SELECT B.*,C.NAME COMPANY_NAME FROM RECEIVE_ITEM A " +
            "LEFT JOIN RECEIVE B ON B.ID = A.MAIN_ID " +
            "LEFT JOIN COMPANY C ON B.COMPANY_ID = C.ID " +
            "WHERE A.ASSET_ID = #{assetId} " +
            "ORDER BY B.CREATE_TIME")
    IPage<AssetUseVo> queryViewByAssetId(Page<AssetUseVo> page, String assetId);

    @Select("SELECT * FROM (SELECT B.*,C.NAME COMPANY_NAME FROM RECEIVE B " +
            "LEFT JOIN COMPANY C ON B.COMPANY_ID = C.ID " +
            "ORDER BY B.CREATE_TIME) TEMP ${ew.customSqlSegment}")
    IPage<AssetUseVo> queryPageView(Page<AssetUseVo> page,@Param(Constants.WRAPPER) QueryWrapper queryWrapper);


    @Select("SELECT SUM(SUM_PRICE) FROM RECEIVE WHERE COMPANY_ID = #{companyId}")
    BigDecimal querySumPrice(String companyId);


}
